//
//  AddAlertViewController.swift
//  SwiftClockDemo
//
//  Created by gwj on 10/15/15.
//  Copyright (c) 2015 gwj. All rights reserved.
//

import UIKit

class AddAlertViewController: UIViewController,UITableViewDelegate,UITableViewDataSource,ChoiceDayDelegate{

    
    @IBOutlet var datePicker: UIDatePicker!
    
    @IBOutlet var choiceTableView: UITableView!
    
    var barButtonSaveTag :NSInteger = 22
    var barButtonCancelTag :NSInteger = 33
    
    var choiceDayArray: NSArray = NSArray()
    
    //MARK: lifeCircle
    override func viewDidLoad() {
        super.viewDidLoad()
        choiceTableView.delegate = self;
        choiceTableView.dataSource = self;
        
            
        let choiceDayViewController : ChoiceDayViewController = ChoiceDayViewController()
        choiceDayViewController.delegate = self
        
        
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //MARK: tableViewDataSource 
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 2
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        if indexPath.row == 0 {
            let cell = tableView.dequeueReusableCellWithIdentifier("AddAlertRepeatTableViewCell",forIndexPath:indexPath)as! AddAlertRepeatTableViewCell
            
            if choiceDayArray.count > 0 {
            
                let dayMutableString: NSMutableString = NSMutableString()
                
                if choiceDayArray.count == 5 {
                

                }else {
                    for  var i = 0; i < choiceDayArray.count ; i++ {
                        dayMutableString .appendString(choiceDayArray.objectAtIndex(i) as! String)
                    }
                    cell.detailTextLabel?.text = dayMutableString as String
                }
            }
            else {
                cell.detailTextLabel?.text = "永不"
            
            }
            
            return cell

        }else {
          let cell = tableView.dequeueReusableCellWithIdentifier("AddAlertSwitchTableViewCell",forIndexPath:indexPath)as! AddAlertSwitchTableViewCell
            
            return cell
        }
    }
    
    //MARK: tableViewDelegate
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
    }
    
    //MARK: ChoiceDayDelegate 
    func choiceDay(arr: NSArray) {
        print(arr.count)
        self.choiceDayArray = arr
        self.choiceTableView.reloadData()
    }
   
    //MARK: ButtonMethord 
    
    @IBAction func didTappedBarButtonItem(sender: UIBarButtonItem) {
        
        if sender.tag == barButtonCancelTag {
            
            }else {
    
            }
        
    }
//      [self .performSegueWithIdentifier("ViewController", sender:self)]
////    }
    
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
